package com.itbbs.user.service.impl;

import com.itbbs.model.userModel.UserInfo;
import com.itbbs.user.mapper.UserInfoMapper;
import com.itbbs.user.service.api.UserInfoService;
import com.itbbs.uuid.UUIDUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author ysk
 * @version 1.0.1
 * @Description 用户个人资料信息的接口的实现类
 * @createTime 2021年06月18日 22:11:00
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Resource
    private UserInfoMapper userInfoMapper;


    @Override
    public UserInfo getUserInfoByUserId(String id) {
        UserInfo userInfo = userInfoMapper.selectUserInfoById(id);
        return userInfo;
    }

    @Override
    public boolean initUserInfo(String id, String username, Date creationTime) {
        // 为用户初始化一个个人资料
        UserInfo userInfo = new UserInfo();
        userInfo.setUserId(UUIDUtil.getUUID());
        userInfo.setUserId(id);
        // 设置默认的昵称,默认的昵称时用户的用户名
        userInfo.setNickName(username);
        userInfo.setCreationTime(creationTime);
        userInfo.setUpdateTime(creationTime);
        userInfo.setUserLevel(1);
        // 设置默认的头像地址
        userInfo.setHeadPortrait("");
        // 保存数据
        int i = userInfoMapper.insertSelective(userInfo);
        return i == 1;
    }
}
